/**
 * DartTest - A Testing framework for Dart
 * Copyright (C) 2012  Dennis Boysen
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.
 *
 * @version 0.01
 * @author Dennis Boysen <dennis@boysen-bordelum.de>
 * @copyright 2012 Dennis Boysen
 * @license GPLv3
 * 
 */
class DartTest {
  
  /**
   * Errorstrings
   * @var List
   */
  List errors;
  
  /*
   * numer of Tests that have been run
   */
  int numTests = 0;
  DartTest() {
    this.errors = new List<String>();
  }
  
  /**
   * Checks, wether the input values are equal
   */
  bool checkEquals(value1, value2) {
    this.numTests++;
    
    if(value1 != value2) {
      this.errors.add("$value1 is not equal to $value2");
      return false;
    }
    return true;
  }
  
  /**
   * Runs the tests (suprise!)
   *
   */
  void run() {
    this.runTests();
    this.checkTests();
  }
  
  /**
   * Check, whether the tests where successfull or not 
   *
   */
  bool checkTests() {
    int errorNum = this.errors.length; 
    int tests = this.numTests;
    
    String currentError = '';
    
    if(errorNum > 0) {
      print("Errors occured!\n");
      for(int i = 0; i < errorNum; i++) {
        currentError = this.errors[i];
        print("$currentError\n");
      }
      print("$errorNum error(s) in $tests tests!");
      return false;
    } else {
      print("No errors occured! Test passed!");
      return true;
    }
  }
  
  /**
   * Runs the Testcases
   *
   * This is needed as long as dart does not provide a reflection API
   *
   * @todo: fix when reflection is provided
   */
  abstract runTests();
}